package cn.iocoder.yudao.module.student.controller.admin.courseintentionstudentinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.student.controller.admin.courseintentionstudentinfo.vo.*;
import cn.iocoder.yudao.module.student.dal.dataobject.courseintentionstudentinfo.CourseIntentionStudentInfoDO;
import cn.iocoder.yudao.module.student.convert.courseintentionstudentinfo.CourseIntentionStudentInfoConvert;
import cn.iocoder.yudao.module.student.service.courseintentionstudentinfo.CourseIntentionStudentInfoService;

@Tag(name = "管理后台 - 意向学员")
@RestController
@RequestMapping("/student/course-intention-student-info")
@Validated
public class CourseIntentionStudentInfoController {

    @Resource
    private CourseIntentionStudentInfoService courseIntentionStudentInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建意向学员")
    @PreAuthorize("@ss.hasPermission('student:course-intention-student-info:create')")
    public CommonResult<Long> createCourseIntentionStudentInfo(@Valid @RequestBody CourseIntentionStudentInfoCreateReqVO createReqVO) {
        return success(courseIntentionStudentInfoService.createCourseIntentionStudentInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新意向学员")
    @PreAuthorize("@ss.hasPermission('student:course-intention-student-info:update')")
    public CommonResult<Boolean> updateCourseIntentionStudentInfo(@Valid @RequestBody CourseIntentionStudentInfoUpdateReqVO updateReqVO) {
        courseIntentionStudentInfoService.updateCourseIntentionStudentInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除意向学员")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('student:course-intention-student-info:delete')")
    public CommonResult<Boolean> deleteCourseIntentionStudentInfo(@RequestParam("id") Long id) {
        courseIntentionStudentInfoService.deleteCourseIntentionStudentInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得意向学员")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('student:course-intention-student-info:query')")
    public CommonResult<CourseIntentionStudentInfoRespVO> getCourseIntentionStudentInfo(@RequestParam("id") Long id) {
        CourseIntentionStudentInfoDO courseIntentionStudentInfo = courseIntentionStudentInfoService.getCourseIntentionStudentInfo(id);
        return success(CourseIntentionStudentInfoConvert.INSTANCE.convert(courseIntentionStudentInfo));
    }

    @GetMapping("/list")
    @Operation(summary = "获得意向学员列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('student:course-intention-student-info:query')")
    public CommonResult<List<CourseIntentionStudentInfoRespVO>> getCourseIntentionStudentInfoList(@RequestParam("ids") Collection<Long> ids) {
        List<CourseIntentionStudentInfoDO> list = courseIntentionStudentInfoService.getCourseIntentionStudentInfoList(ids);
        return success(CourseIntentionStudentInfoConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得意向学员分页")
    @PreAuthorize("@ss.hasPermission('student:course-intention-student-info:query')")
    public CommonResult<PageResult<CourseIntentionStudentInfoRespVO>> getCourseIntentionStudentInfoPage(@Valid CourseIntentionStudentInfoPageReqVO pageVO) {
        PageResult<CourseIntentionStudentInfoDO> pageResult = courseIntentionStudentInfoService.getCourseIntentionStudentInfoPage(pageVO);
        return success(CourseIntentionStudentInfoConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出意向学员 Excel")
    @PreAuthorize("@ss.hasPermission('student:course-intention-student-info:export')")
    @OperateLog(type = EXPORT)
    public void exportCourseIntentionStudentInfoExcel(@Valid CourseIntentionStudentInfoExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<CourseIntentionStudentInfoDO> list = courseIntentionStudentInfoService.getCourseIntentionStudentInfoList(exportReqVO);
        // 导出 Excel
        List<CourseIntentionStudentInfoExcelVO> datas = CourseIntentionStudentInfoConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "意向学员.xls", "数据", CourseIntentionStudentInfoExcelVO.class, datas);
    }

}
